/**
 * @param {number[]} dist
 * @param {number} hour
 * @return {number}
 */
 var minSpeedOnTime = function(dist, hour) {
    if(dist.length-1 > hour)
        return -1
    let sum = dist.reduce((pre,cur) => pre+cur)
    let max = sum/hour
    if(Number.isInteger(max))
        return max
    let ans = Math.ceil(max)
    let l = ans, r = 10000000
    while(l < r){
        let m = (l+r) >>1
        if(check(m)){
            r = m
        }else
            l = m+1
    }
    return l

    function check(ans){
        let sum = 0
        for(let i = 0; i<dist.length; i++){
            if(i !== dist.length-1){
                sum += Math.ceil(dist[i]/ans)
            }else
                sum += dist[i]/ans
        }
        return sum <= hour
    }
};
